import os
import pymysql
from dotenv import load_dotenv

# Load environment variables from .env file
load_dotenv()

def check_database_data():
    db_config = {
        'host': os.getenv('DB_HOST', 'localhost'),
        'port': int(os.getenv('DB_PORT', 3306)),
        'user': os.getenv('DB_USER', 'root'),
        'password': os.getenv('DB_PASSWORD', '123456'),
        'database': os.getenv('DB_NAME', 'zpsjfx'),
        'charset': 'utf8mb4',
        'cursorclass': pymysql.cursors.DictCursor
    }

    try:
        connection = pymysql.connect(**db_config)
        print("Database connection successful.")
        with connection.cursor() as cursor:
            # Check users table
            cursor.execute("SELECT COUNT(*) as count FROM users")
            user_count = cursor.fetchone()['count']
            print(f"'users' table contains: {user_count} records.")

            # Check boss_jobs table
            cursor.execute("SELECT COUNT(*) as count FROM boss_jobs")
            job_count = cursor.fetchone()['count']
            print(f"'boss_jobs' table contains: {job_count} records.")

    except pymysql.Error as e:
        print(f"Database connection failed: {e}")
    finally:
        if 'connection' in locals() and connection.open:
            connection.close()

if __name__ == "__main__":
    check_database_data()

